<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2014 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace Think\Template\TagLib;
use Think\Template\TagLib;
/**
 * JQ 自定义标签库驱动
 */
class Jq extends TagLib{
    // 标签定义
    protected $tags   =  array(
        // 标签定义： attr 属性列表 close 是否闭合（0 或者1 默认1） alias 标签别名 level 嵌套层次
        'list' => array('attr' => 'type,order,limit,where,item','close' => 1),
        );
    
    //数据查询
    public function _list($attr,$content) {
        $type = $attr['type']; //要查询的数据表
        $order = $attr['order'];  //排序
        $limit = $attr['limit']==null ? 10 : $attr['limit'];//多少条数据
        $where = $attr['where']; //查询条件
        $item = $attr['item']==null ? 1 : $attr['item'];//循环变量
        $str = '<?php ';
        $str .= '$result = M('.$type.')->where($where)->order("'. $order . '")->limit('.$limit.')->select();';
        switch ($item){
            case 1:
                $str .= 'foreach ($result as $v):';
                break;
            case 2:
                $str .= 'foreach ($result as $vv):';
                break;
            case 3:
                $str .= 'foreach ($result as $vvv):';
                break;
            default:
                $str .= 'foreach ($result as $v):';
        }
        $str .= '?>';
        $str .= $content;
        $str .= '<?php endforeach ?>';
        return $str;
    }
    
    
    
}